package com.controller;

import com.pojo.WhCgMapping;
import com.service.WhCgMappingService;
import com.util.Pager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/base/whCgMapping")
public class WhCgMappingHandler {
    @Resource
    private WhCgMappingService whCgMappingService;

    /**
     * 导出
     * @param format
     * @return
     */
    @RequestMapping("/report")
    public ModelAndView report(String format) {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("format", format);
        return new ModelAndView("whCgMappingReport", model);
    }

    @RequestMapping("/searchByWhCgMappingPager")
    public Pager<WhCgMapping> searchByWhCgMappingPager(WhCgMapping whCgMapping,Integer limit,Integer offset){
        Pager<WhCgMapping> pager=new Pager<>();
        pager.setLimit(limit);
        pager.setOffSet(offset);
        pager.setCondition(whCgMapping);
        return whCgMappingService.searchPager(pager);
    }
    @RequestMapping("/addWhCgMapping")
    public String addWhCgMapping(WhCgMapping whCgMapping){
        String msg="添加失败！";
        int i =whCgMappingService.add(whCgMapping);
        if(i>0){
            msg="添加成功！";
        }
        return msg;
    }

    @RequestMapping("/delWhCgMapping")
    public String delWhCgMapping(Integer id){
        String msg="删除失败！";
        int i =whCgMappingService.del(id);
        if(i>0){
            msg="删除成功！";
        }
        return msg;
    }


    @RequestMapping("/updateWhCgMapping")
    public String updateWhCgMapping(WhCgMapping whCgMapping){
        String msg="修改失败！";
        int i = whCgMappingService.update(whCgMapping);
        if(i>0){
            msg="修改成功！";
        }
        return msg;
    }

}
